package tw.asap.plus.entity;

import android.text.TextUtils;

import tw.asap.plus.app.NearApplication;
import tw.asap.plus.common.ConstValue;
import tw.asap.plus.utils.SPUtil;

public class User {
    public String token;
    public String meruser;
    public String mobile;

    public static String getUserToken() {

        return SPUtil.getInstance(NearApplication.getNearApplicationContext()).getString(ConstValue.Sp.USER_TOKEN, "");
    }

    public static void cacheUserToken(String userToken) {
        SPUtil.getInstance(NearApplication.getNearApplicationContext()).save(ConstValue.Sp.USER_TOKEN, userToken);
    }

    public static String getCachedUserId() {
        return SPUtil.getInstance(NearApplication.getNearApplicationContext()).getString(ConstValue.Sp.APP_ID, "");
    }

    public static void cacheUserId(String userId) {
        SPUtil.getInstance(NearApplication.getNearApplicationContext()).save(ConstValue.Sp.APP_ID, userId);
    }

    public static void cacheUserMobile(String mobile){
        SPUtil.getInstance(NearApplication.getNearApplicationContext()).save(ConstValue.Sp.USERNAME,mobile);
    }

    public static String getUserName(){
        return SPUtil.getInstance(NearApplication.getNearApplicationContext()).getString(ConstValue.Sp.USERNAME,"");
    }

    public static boolean hasLogin() {
        return !TextUtils.isEmpty(getUserToken());
    }

    public static void logOut() {
        SPUtil.getInstance(NearApplication.getNearApplicationContext()).save(ConstValue.Sp.USER_TOKEN, "");
        SPUtil.getInstance(NearApplication.getNearApplicationContext()).save(ConstValue.Sp.APP_ID, "");
    }
}
